package com.sbl.bajw.pc.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sbl.bajw.common.Page;
import com.sbl.bajw.pc.model.policeCaseTModel;
import com.sbl.bajw.pc.service.StreetCaseTModelService;
import com.sbl.bajw.util.JsonUtil;

@Controller
@RequestMapping("/streetCaseTModel")
public class StreetCaseTModelAction {

	@Resource
	private StreetCaseTModelService service;
	
	@RequestMapping(value = "/getAllByOrg")
	public @ResponseBody String	getAllByOrg(HttpServletRequest request, HttpServletResponse response){
		String orgcode = request.getParameter("orgcode");
		String code = request.getParameter("code");
		List<policeCaseTModel> list = new ArrayList<policeCaseTModel>();
		String json = "";
		System.out.println(orgcode);
		HashMap<String, Object> parm = new HashMap<String, Object>();
		parm.put("orgcode", orgcode);
		if(code.equals("3")){
			list = service.getAllByOrg(parm);
		} else if(code.equals("4")) {
			list = service.getAllByOrgAndLevel(parm);
		} else if(code.equals("5")) {
			list = service.getAllByOrgAndOrgLevel(parm);
		}
		json = JsonUtil.ConvertArrayToJson(list);
		return json;
	}
	
	@RequestMapping(value = "/getModelsByOrgLevel")
	public @ResponseBody String getModelsByOrgLevel(@RequestParam(value="fulldeptid",required=false) String fulldeptid,
			@RequestParam(value="orglevel",required=false) String orglevel,
			@RequestParam(value="jingqingField",required=false) String jingqingField){
		HashMap<String, Object> parm = new HashMap<String, Object>();
		parm.put("fulldeptid", fulldeptid+"%");
		parm.put("orglevel", orglevel);
		if(jingqingField != null && !jingqingField.equals("")){
			Page page = new Page();
			page.setPageIndex(1);
			page.setPageSize(99999);
			page.setOrderString(jingqingField + " DESC ");
			parm.put("pageParameter", page);
		}
		
		List<HashMap<String, String>> list = service.getModelsByOrgLevel(parm);
		String json = JsonUtil.ConvertArrayToJson(list);
		return json;
	}
	
	@RequestMapping(value = "/getModelsById")
	public @ResponseBody String getModelsById(@RequestParam(value="id") String id){
		
		policeCaseTModel model = service.getModelsById(id);
		String json = JsonUtil.ConvertObjectToJson(model);
		return json;
	}
}
